// UseNetVar_ADlg.cpp : implementation file
//

#include "stdafx.h"
#include "UseNetVar_A.h"
#include "UseNetVar_ADlg.h"
#include "../Common/Person.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUseNetVar_ADlg dialog

CUseNetVar_ADlg::CUseNetVar_ADlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUseNetVar_ADlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUseNetVar_ADlg)
	m_strName = _T("");
	m_nAge = 0;
	m_dHeight = 0.0;
	m_strName2 = _T("");
	m_dHeight2 = 0.0;
	m_nAge2 = 0;
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CUseNetVar_ADlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUseNetVar_ADlg)
	DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
	DDX_Text(pDX, IDC_EDIT_AGE, m_nAge);
	DDX_Text(pDX, IDC_EDIT_HEIGHT, m_dHeight);
	DDX_Text(pDX, IDC_EDIT_NAME2, m_strName2);
	DDX_Text(pDX, IDC_EDIT_HEIGHT2, m_dHeight2);
	DDX_Text(pDX, IDC_EDIT_AGE2, m_nAge2);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUseNetVar_ADlg, CDialog)
	//{{AFX_MSG_MAP(CUseNetVar_ADlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON_UPDATE_TO_B, OnButtonUpdateToB)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUseNetVar_ADlg message handlers

BOOL CUseNetVar_ADlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	SetTimer(1, 500, NULL);
	NetVarServerInitial();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CUseNetVar_ADlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

HCURSOR CUseNetVar_ADlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CUseNetVar_ADlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	m_strName2 = NetVar_Name;
	m_nAge2 = NetVar_Age;
	m_dHeight2 = NetVar_Height;
	
	CString strTmp;
	strTmp.Format(_T("%lf"), m_dHeight2);
	
	SetDlgItemText(IDC_EDIT_NAME2, m_strName2);
	SetDlgItemInt(IDC_EDIT_AGE2, m_nAge2);
	SetDlgItemText(IDC_EDIT_HEIGHT2, strTmp);

	CDialog::OnTimer(nIDEvent);
}

void CUseNetVar_ADlg::OnButtonUpdateToB() 
{
	// TODO: Add your control notification handler code here
	if (!UpdateData())
	{
		return;
	}
	
	NetVar_Name = m_strName;
	NetVar_Age = m_nAge;
	NetVar_Height = m_dHeight;

}
